/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package uimigration.UIModel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import uimigration.Interactions.Behaviour;
import uimigration.UIModel.Event;
import uimigration.UIModel.Property;
import uimigration.UIModel.UIElement;
import uimigration.UIModel.UIModelPackage;
import uimigration.WidgetsModel.Widget;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>UI Element</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link uimigration.UIModel.impl.UIElementImpl#getName <em>Name</em>}</li>
 *   <li>{@link uimigration.UIModel.impl.UIElementImpl#getId <em>Id</em>}</li>
 *   <li>{@link uimigration.UIModel.impl.UIElementImpl#getEvents <em>Events</em>}</li>
 *   <li>{@link uimigration.UIModel.impl.UIElementImpl#getProperties <em>Properties</em>}</li>
 *   <li>{@link uimigration.UIModel.impl.UIElementImpl#getWidgetType <em>Widget Type</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class UIElementImpl extends EObjectImpl implements UIElement {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected static final int ID_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected int id = ID_EDEFAULT;

	/**
	 * The cached value of the '{@link #getEvents() <em>Events</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEvents()
	 * @generated NOT
	 * @ordered
	 */
	protected EList<Event> events;

	/**
	 * The cached value of the '{@link #getProperties() <em>Properties</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProperties()
	 * @generated NOT
	 * @ordered
	 */
	protected EList<Property> properties;

	/**
	 * The cached value of the '{@link #getBehaviour() <em>Behaviour</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBehaviour()
	 * @generated NOT
	 * @ordered
	 */
	protected EList<Behaviour> behaviour;

	/**
	 * The cached value of the '{@link #getWidgetType() <em>Widget Type</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getWidgetType()
	 * @generated
	 * @ordered
	 */
	protected Widget widgetType;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected UIElementImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return UIModelPackage.Literals.UI_ELEMENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, UIModelPackage.UI_ELEMENT__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getId() {
		return id;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setId(int newId) {
		int oldId = id;
		id = newId;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, UIModelPackage.UI_ELEMENT__ID, oldId, id));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public EList<Event> getEvents() {
		if (events == null) {
			events = new EObjectContainmentEList<Event>(Event.class, this,
					UIModelPackage.UI_ELEMENT__EVENTS);
		}
		return events;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public EList<Property> getProperties() {
		if (properties == null) {
			properties = new EObjectContainmentEList<Property>(Property.class,
					this, UIModelPackage.UI_ELEMENT__PROPERTIES);
		}
		return properties;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Widget getWidgetType() {
		return widgetType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetWidgetType(Widget newWidgetType,
			NotificationChain msgs) {
		Widget oldWidgetType = widgetType;
		widgetType = newWidgetType;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, UIModelPackage.UI_ELEMENT__WIDGET_TYPE, oldWidgetType, newWidgetType);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
			case UIModelPackage.UI_ELEMENT__EVENTS:
				return ((InternalEList<?>)getEvents()).basicRemove(otherEnd, msgs);
			case UIModelPackage.UI_ELEMENT__PROPERTIES:
				return ((InternalEList<?>)getProperties()).basicRemove(otherEnd, msgs);
			case UIModelPackage.UI_ELEMENT__WIDGET_TYPE:
				return basicSetWidgetType(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case UIModelPackage.UI_ELEMENT__NAME:
				return getName();
			case UIModelPackage.UI_ELEMENT__ID:
				return getId();
			case UIModelPackage.UI_ELEMENT__EVENTS:
				return getEvents();
			case UIModelPackage.UI_ELEMENT__PROPERTIES:
				return getProperties();
			case UIModelPackage.UI_ELEMENT__WIDGET_TYPE:
				return getWidgetType();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case UIModelPackage.UI_ELEMENT__NAME:
				setName((String)newValue);
				return;
			case UIModelPackage.UI_ELEMENT__ID:
				setId((Integer)newValue);
				return;
			case UIModelPackage.UI_ELEMENT__EVENTS:
				getEvents().clear();
				getEvents().addAll((Collection<? extends Event>)newValue);
				return;
			case UIModelPackage.UI_ELEMENT__PROPERTIES:
				getProperties().clear();
				getProperties().addAll((Collection<? extends Property>)newValue);
				return;
			case UIModelPackage.UI_ELEMENT__WIDGET_TYPE:
				setWidgetType((Widget)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case UIModelPackage.UI_ELEMENT__NAME:
				setName(NAME_EDEFAULT);
				return;
			case UIModelPackage.UI_ELEMENT__ID:
				setId(ID_EDEFAULT);
				return;
			case UIModelPackage.UI_ELEMENT__EVENTS:
				getEvents().clear();
				return;
			case UIModelPackage.UI_ELEMENT__PROPERTIES:
				getProperties().clear();
				return;
			case UIModelPackage.UI_ELEMENT__WIDGET_TYPE:
				setWidgetType((Widget)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case UIModelPackage.UI_ELEMENT__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case UIModelPackage.UI_ELEMENT__ID:
				return id != ID_EDEFAULT;
			case UIModelPackage.UI_ELEMENT__EVENTS:
				return events != null && !events.isEmpty();
			case UIModelPackage.UI_ELEMENT__PROPERTIES:
				return properties != null && !properties.isEmpty();
			case UIModelPackage.UI_ELEMENT__WIDGET_TYPE:
				return widgetType != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(", id: ");
		result.append(id);
		result.append(')');
		return result.toString();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setWidgetType(Widget newWidgetType) {
		if (newWidgetType != widgetType) {
			NotificationChain msgs = null;
			if (widgetType != null)
				msgs = ((InternalEObject)widgetType).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - UIModelPackage.UI_ELEMENT__WIDGET_TYPE, null, msgs);
			if (newWidgetType != null)
				msgs = ((InternalEObject)newWidgetType).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - UIModelPackage.UI_ELEMENT__WIDGET_TYPE, null, msgs);
			msgs = basicSetWidgetType(newWidgetType, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, UIModelPackage.UI_ELEMENT__WIDGET_TYPE, newWidgetType, newWidgetType));
	}

	public void setWidget(Widget newWidget)
	{
		widgetType =newWidget;
	}
	
} //UIElementImpl
